package com.example.controller.adm;

import com.example.pojo.Chamber;
import com.example.service.impl.ChamberServiceImpl;
import com.example.vo.ResultVo;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import io.swagger.annotations.Api;

import java.util.Arrays;
import java.util.List;

/**
 * <p>
 * 会议室信息表 前端控制器
 * </p>
 *hy
 * @author wsl
 * @since 2022-04-24
 */
@RestController
@RequestMapping("/adm/hy")
@Api(tags = "会议室信息表",value = "")
public class ChamberController {

    @Autowired
    private ChamberServiceImpl chamberService;

    @GetMapping("/query")
    @ApiOperation(value = "会议室信息")
    public PageInfo<Chamber> list(Integer maxCapacity,Integer status){
        return chamberService.selectChamber(maxCapacity,status);
    }

    @PostMapping("/add")
    @ApiOperation(value = "新增会议室")
    public ResultVo addChamber(@RequestBody Chamber chamber){
        System.out.println(chamber);
        if (chamberService.save(chamber)) {
            return ResultVo.success("新增会议成功");
        }
        return ResultVo.error("新增会议室失败");
    }

    @PutMapping("/update")
    @ApiOperation(value = "根据id修改会议室状态")
    public ResultVo updateChamber(@RequestBody Chamber chamber){
        if (chamberService.updateById(chamber)) {
            return ResultVo.success("修改成功");
        }
        return ResultVo.error("修改失败");
    }

    @DeleteMapping("/delete")
    @ApiOperation(value = "根据编号删除会议室")
    public ResultVo deleteChamberById(Integer[] ids){
        return chamberService.removeByIds(Arrays.asList(ids)) ? ResultVo.success("删除成功") : ResultVo.error("删除失败");
    }


}
